package com.bw1806.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bw1806.entity.Result;
import com.bw1806.entity.ResultPage;
import com.bw1806.pojo.TAihaoKey;
import com.bw1806.pojo.TType;
import com.bw1806.pojo.TbBrand;
import com.bw1806.pojo.TbItemCat;
import com.bw1806.service.TbBrandService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1310:59
 */
@RestController
@RequestMapping("tbBrand")
public class TbBrandController {

    @Reference
    private TbBrandService tbBrandService;

    @Resource
    private RedisTemplate<String,String> redisTemplate;

    /**
     * 获取当前登录用户
     * @return
     */
    @RequestMapping("name")
    public Map<String,String> name(){
        redisTemplate.opsForValue().set("wangyue","wangyue");
        String name=redisTemplate.opsForValue().get("wangyue");
        // String name= SecutityUtils.getLoginUser();
        Map<String,String> map=new HashMap<String,String>();
        map.put("loginName", name);
        return map ;
    }

    /**
     * 查询分页列表
     * @param tbBrand
     * @param pageSize
     * @param pageNum
     * @return
     */
    @RequestMapping("list")
    public ResultPage<TbBrand> list(@RequestBody TbBrand tbBrand, int pageSize, int pageNum) {
        return tbBrandService.list(tbBrand,pageSize,pageNum);
    }

    /**
     * 根据主键查询单条
     * @param id
     * @return
     */
    @RequestMapping("getById")
    public TbBrand getById(Long id) {
        return tbBrandService.getById(id);
    }

    /**
     * 保存方法
     * @param tbBrand
     * @return
     */
    @RequestMapping("save")
    public Result save(@RequestBody TbBrand tbBrand) {
        try{
            tbBrandService.save(tbBrand);
            return new Result(true,"成功");
        } catch (Exception e){
            e.printStackTrace();
            return new Result(false,"失败");
        }

    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("deletbth")
    public Result deletbth(Long[] ids) {
        try{
            tbBrandService.deletbth(ids);
            return new Result(true,"成功");
        } catch (Exception e){
            return new Result(false,"失败");
        }

    }

    /**
     * 返回类型列表
     * @param
     * @return
     */
    @RequestMapping("getTypes")
    public List<TType> getTypes() {
        return tbBrandService.getTypes();
    }
    /**
     * 返回类型列表
     * @param
     * @return
     */
    @RequestMapping("getTAihaoKeys")
    public List<TAihaoKey> getTAihaoKeys() {
        return tbBrandService.getTAihaoKeys();
    }

    /**
     * 返回类型列表
     * @param
     * @return
     */
    @RequestMapping("getTbItemCats/{pid}")
    public List<TbItemCat> getTbItemCats(@PathVariable Long pid) {
        return tbBrandService.getTbItemCats(pid);
    }
}
